;
(function() {
	module.exports = {
		prefix: "/bus/achs",
		get: {
			"/": function() {
				var bus = role.getBus(this);
				var query = this.request.query;
				var achs = bus.getAchs(query.num, query.page)
				this.body = ResponObj("json", achs);
			},
			"/detail": function() {
				var bus = role.getBus(this);
				var query = this.request.query;
				var achs_detail = bus.getAchsDetail(query.num, query.page)
				this.body = ResponObj("json", achs_detail);
			},
			"/with_page_info": function() {
				var bus = role.getBus(this);
				var query = this.request.query;
				var info = bus.getAchsDetail_PageInfo(query.num, query.page)
				this.body = ResponObj("json", info);
			},
			"/with_type_and_page_info": function() {
				var bus = role.getBus(this);
				var query = this.request.query;
				var info = bus.getAchsWithType_PageInfo(query.type, query.num, query.page)
				this.body = ResponObj("json", info);
			},
			"/find": function() {
				var query = this.request.query;
				var bus = role.getBus(this);
				var ach_key = query.ach_key || "";
				if (!ach_key) {
					throwCusError("搜索的关键字不可为空")
				}
				var achs = bus.findAchs(query.num, query.page, ach_key);
				this.body = ResponObj("json", achs);
			}
		},
		put: {
			"/status/ol未发货_to_ol未收货/:ach_id": function() {
				var bus = role.getBus(this);
				var ach_id = this.params.ach_id;
				var body = this.request.body;
				var express_info = body.express_info;
				if (ach_id && express_info) {
					var result_status = bus.state_ach_ol未发货_to_ol未收货({
						ach_id: ach_id,
						express_info: express_info
					});
					this.body = ResponObj("json", result_status);
				} else {
					throwCusError("参数错误")
				}
			},
			"/status/未发货_to_已发货/:ach_id": function() {
				var bus = role.getBus(this);
				var ach_id = this.params.ach_id;
				var body = this.request.body;
				var express_info = body.express_info;
				if (ach_id && express_info) {
					var result_status = bus.state_ach_未发货_to_已发货({
						ach_id: ach_id,
						express_info: express_info
					});
					this.body = ResponObj("json", result_status);
				} else {
					throwCusError("参数错误")
				}
			},
			"/status/未收货未付款_to_交易完成/:ach_id": function() {
				var bus = role.getBus(this);
				var ach_id = this.params.ach_id;
				if (ach_id) {
					var result_status = bus.state_ach_未收货未付款_to_交易完成(ach_id);
					this.body = ResponObj("json", result_status);
				} else {
					throwCusError("参数错误")
				}
			},
			"/status/face未付款_to_face交易完成/:ach_id": function() {
				var bus = role.getBus(this);
				var ach_id = this.params.ach_id;
				if (ach_id) {
					var result_status = bus.state_ach_face未付款_to_face交易完成(ach_id);
					this.body = ResponObj("json", result_status);
				} else {
					throwCusError("参数错误")
				}
			},
			//自定义订单应付金额
			"/custom_cash/:ach_id": function() {
				var bus = role.getBus(this);
				var ach_id = this.params.ach_id;
				var body = this.request.body;
				if (!ach_id) {
					throwCusError("参数错误")
				}
				var ach = bus.ach_change_cash(ach_id, body.cus_cash);
				this.body = ResponObj("json", ach);
			},
			"/hidden_ach/:ach_id": function() {

				var bus = role.getBus(this);
				var ach_id = this.params.ach_id;
				var body = this.request.body;
				if (!ach_id) {
					throwCusError("参数错误")
				}
				bus.hiddenAch(ach_id);

				if (body.return_url) {
					method = module.exports.get[body.return_url];
					if (method) {
						method.apply(this, arguments)
					}
				} else {
					this.body = ResponObj("string", "已经隐藏");
				}
			}
		}
	}
	var role = require("./role");
	var BusCon = require("../../core/bus/_con");
	var UserCon = require("../../core/user/_con");
	var GoodsCon = require("../../core/goods/_con");
	var AchCon = require("../../core/ach/_con");
	var db = require("../../core/db/index");
	var config = require("../../core/_include/config");
	var ResponObj = require("../_include/responObj");
}());